define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'daili/index' + location.search,
                    // add_url: 'daili/add',
                    // edit_url: 'daili/edit',
                    del_url: 'daili/del',
                    multi_url: 'daili/multi',
                    import_url: 'daili/import',
                    table: 'daili',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'imgb', title: __('Imgb'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'imga', title: __('Imga'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},

                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'addname', title: __('Address_id'), operate: false},


                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'ajax',
                                    title: __('通过'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa  fa-check',
                                    confirm: '确认通过审核？',
                                    url: 'daili/successdaili',
                                    success: function (data, ret) {
                                        location.reload();
                                    },
                                    visible: function (row) {

                                        if (row.status==1){
                                            return false;
                                        }else{
                                            return true;
                                        }



                                    },

                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
